<template>
  <div class="app-container">
    <el-button @click="showDialog">显示浮层</el-button>
    <div v-if="dialogVisible" class="dialog" >
      <p>这是浮层的内容</p>
      <div class="dialog-footer">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="closeDialog">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";

const dialogVisible = ref(false);

const showDialog = () => {
  dialogVisible.value = true;
};

const closeDialog = () => {
  dialogVisible.value = false;
};
</script>

<style lang="scss" scoped>

.app-container{
  display: flex;
  justify-content: center;
  align-items: center;
  width: 300px;
  height: 200px;
  border: 1px solid #ccc;
  position: relative;
}


.dialog {
  position: absolute;
  top: 100%; /* 使对话框显示在按钮下方 */
  left: 0;
  transform: translateY(10px); /* 可以调整这个值来增加一些间距 */
  background-color: white;
  border: 1px solid #ccc;
  padding: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000; /* 确保对话框在其他内容之上 */
  width: 200px; /* 根据需要调整宽度 */
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}
</style>
